﻿using System;
using System.Web.UI.WebControls;
using MaLu.Common;
using MaLu.Data;
using System.Data;
using System.Text;
using Wicresoft.Framework.Organization;
using MaLu.Framework.Common;

namespace MaluJg.web.StatsIn
{
    public partial class SEdit : SPage
    {
        protected string SType = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
          

            SType = Request["type"] ?? "fbooth";
            if (!IsPostBack)
            {
                this.Title = "扶持资金添加";
                //Department mainD = OrganizationHelper.GetDepartmentInfo(CurrentUser.MainDepartmentID);
                //string[] ids = mainD.IDPath.Split('/');
                //if (ids.Length >= 4)
                //    DepartmentID = new Guid(ids[3]);
                //else
                //    DepartmentID = new Guid(ids[ids.Length - 1]);


                Binddata();


            }

        }
        protected int RecordID
        {
            get
            {
                int gd = 0;
                if (Request["ID"] != null)
                {
                    int.TryParse(Request["ID"] ?? "0", out gd);

                }
                else
                {
                    if (ViewState["ID"] != null)
                        gd = (int)ViewState["ID"];


                }
                if (ViewState["ID"] == null)
                    ViewState["ID"] = gd;
                return gd;
            }
            set
            {
                ViewState["ID"] = value;
            }

        }
        protected void lbtnSave_Click(object sender, EventArgs e)
        {
            switch (SType)
            {
                case "fhuafei":
                    uFertilizer1.SaveData();
                    break;
                case "fbooth":
                    uBooth1.SaveData();
                    break;
                case "fcold":
                    uCold1.SaveData();
                    break;
                case "fgreen":
                    uGreen1.SaveData();
                    break;
                case "fmembrane":
                    uMembrane1.SaveData();
                    break;
                case "fpackage":
                    uPackage1.SaveData();
                    break;
                    
                default: break;

            }

            Page.ClientScript.RegisterClientScriptBlock(GetType(),"save","<script>alert('成功保存！');window.close();</script>");
        }

        private void Binddata()
        {
            uFertilizer1.Visible = false;
            uBooth1.Visible = false;
            uCold1.Visible = false;
            uGreen1.Visible = false;
            uMembrane1.Visible = false;
            uPackage1.Visible = false;
            switch (SType)
            {
                case "fhuafei":
                    uFertilizer1.Visible = true;
                    uFertilizer1.LoadData(); break;
                case "fbooth":
                    uBooth1.Visible = true;
                    uBooth1.LoadData(); break;
                case "fcold":
                    uCold1.Visible = true;
                    uCold1.LoadData(); break;
                case "fgreen":
                    uGreen1.Visible = true;
                    uGreen1.LoadData(); break;

                case "fmembrane":
                    uMembrane1.Visible = true;
                    uMembrane1.LoadData(); break;
                case "fpackage":
                    uPackage1.Visible = true;
                    uPackage1.LoadData(); break;
                default: break;

            }

          
        }
    }
}
